/*
 * GraphicChart.java
 *
 * Created on 26 de abril de 2007, 08:06 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RectangleInsets;
import org.jfree.chart.*;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.time.*;
import org.jfree.data.xy.XYDataset;
import javax.swing.JPanel;
import java.text.SimpleDateFormat;
import java.awt.Color;

/**
 *
 * @author William Santamaria
 */
public class GraphicChart extends ApplicationFrame {

    public TimeSeries s1 = new TimeSeries("", Millisecond.class);
    public TimeSeries s2 = new TimeSeries("", Millisecond.class);
    public TimeSeries s3 = new TimeSeries("", Millisecond.class);

    public GraphicChart(String title) {
        super(title);
        ChartPanel chartPanel = (ChartPanel) createDemoPanel();
//        chartPanel.setPreferredSize(new java.awt.Dimension(500, 180));
        chartPanel.setMouseZoomable(true, false);
        setContentPane(chartPanel);
        this.pack();
//        this.setVisible(true);
    }

    private JFreeChart createChart(XYDataset dataset) {

        JFreeChart chart = ChartFactory.createTimeSeriesChart(
            "",  // title
            "",  // x-axis label
            "",  // y-axis label
            dataset,            // data
            false,              // create legend?
            false,              // generate tooltips?
            false               // generate URLs?
        );

        chart.setBackgroundPaint(Color.white);

        XYPlot plot = (XYPlot) chart.getPlot();
        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);
        plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
        plot.setDomainCrosshairVisible(false);
        plot.setRangeCrosshairVisible(false);

        DateAxis axis = (DateAxis) plot.getDomainAxis();
        axis.setDateFormatOverride(new SimpleDateFormat(""));

        return chart;
    }

    private XYDataset createDataset() {

        TimeSeriesCollection dataset = new TimeSeriesCollection();
        s1.setMaximumItemCount(50);
        s2.setMaximumItemCount(50);
        s3.setMaximumItemCount(50);
        dataset.addSeries(s1);
        dataset.addSeries(s2);
        dataset.addSeries(s3);

        return dataset;
    }

    public JPanel createDemoPanel() {
        JFreeChart chart = createChart(createDataset());
        return new ChartPanel(chart);
    }

}
